"use client" import { useState, useEffect } from "react" import Link from "next/link" import { useParams } from "next/navigation" import { Highlight, themes } from "prism-react-renderer" import { getLeaderboardEntry, type LeaderboardEntry } from "@/lib/api" import { cn } from "@/lib/utils" import { StatsGrid, AccuracyByType, LatencyTable, RetrievalMetrics, EvaluationList, type EvaluationResult, } from "@/components/benchmark-results" type Tab = "overview" | "results" | "code" export default function LeaderboardEntryPage() { const params = useParams() const id = parseInt(params.id as string) const [entry, setEntry] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [activeTab, setActiveTab] = useState("overview") const [activeCodeFile, setActiveCodeFile] = useState("index.ts") useEffect(() => { loadEntry() }, [id]) async function loadEntry() { try { setLoading(true) const data = await getLeaderboardEntry(id) setEntry(data) setError(null) if (data.providerCode) { try { const files = JSON.parse(data.providerCode) const fileNames = Object.keys(files) if (fileNames.length > 0) { setActiveCodeFile(fileNames[0]) } } catch { // Not JSON, just raw code } } } catch (e) { setError(e instanceof Error ? e.message : "Failed to load entry") } finally { setLoading(false) } } if (loading) { return (
) } if (error || !entry) { return (

{error || "Entry not found"}

Back to Leaderboard
) } let codeFiles: Record = {} try { codeFiles = JSON.parse(entry.providerCode) } catch { codeFiles = { "index.ts": entry.providerCode } } const codeFileNames = Object.keys(codeFiles) const evaluations: EvaluationResult[] = entry.evaluations || [] const addedDate = new Date(entry.addedAt) const formattedDate = `${addedDate.getFullYear()}-${String(addedDate.getMonth() + 1).padStart(2, "0")}-${String(addedDate.getDate()).padStart(2, "0")}` const tabs: Tab[] = ["overview", "results", "code"] const statsCards = [ { label: "accuracy", value: `${(entry.accuracy * 100).toFixed(1)}%`, subtext: `${entry.correctCount}/${entry.totalQuestions} correct`, }, { label: "questions", value: entry.totalQuestions, }, { label: "judge model", value: entry.judgeModel, mono: true, }, { label: "answering model", value: entry.answeringModel, mono: true, }, ] return (
Leaderboard / {entry.version}

{entry.provider} / {entry.version}

benchmark:{" "} {entry.benchmark} original run:{" "} {entry.runId} added: {formattedDate}
{entry.notes && (
notes: {entry.notes}
)}
{tabs.map((tab) => ( ))}
{activeTab === "overview" && (
)} {activeTab === "results" && } {activeTab === "code" && ( )}
) } function CodeTab({ codeFiles, codeFileNames, activeCodeFile, setActiveCodeFile, }: { codeFiles: Record codeFileNames: string[] activeCodeFile: string setActiveCodeFile: (file: string) => void }) { const code = codeFiles[activeCodeFile] || "// No code available" return (
{codeFileNames.length > 1 && (
{codeFileNames.map((fileName, index) => { const isSelected = activeCodeFile === fileName const isFirst = index === 0 const isLast = index === codeFileNames.length - 1 return ( ) })}
)}
{activeCodeFile}
{({ style, tokens, getLineProps, getTokenProps }) => (
              {tokens.map((line, i) => (
                
{i + 1} {line.map((token, key) => ( ))}
))}
)}
) }